package com.sskj.fabi.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.bean.PublishRecordBean;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.fragment.PublishRecordFragment;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


public class PublishRecordFragmentPresenter extends BasePresenter<PublishRecordFragment> {
    public Flowable<List<PublishRecordBean>> getData(String page, String pageSize, boolean isBuy) {
        return httpService.getPublishRecord(page, pageSize, isBuy)
                .converter(new JsonConverter<HttpData<PageBean<PublishRecordBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(haiPageBeanHttpData -> haiPageBeanHttpData.getData().getList());
    }

    public void cancelPublishOrder(boolean isBuy, String id) {
        httpService.cancelPublishOrder(isBuy, id)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.cancelSuccess();
                        }
                    }
                });
    }
}
